package com.pms.controller;

import com.pms.dto.VehiclePageQueryDTO;
import com.pms.dto.VehicleSaveDTO;
import com.pms.result.PageResult;
import com.pms.result.Result;
import com.pms.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "车辆相关接口")
@RestController
@RequestMapping("/vehicle")
@Slf4j
public class VehicleController {

    @Autowired
    private VehicleService vehicleService;

    @ApiOperation("新增车辆")
    @PostMapping("/save")
    public Result<String> save(@RequestBody VehicleSaveDTO vehicleSaveDTO){
        log.info("新增车辆,{}",vehicleSaveDTO);
        vehicleService.save(vehicleSaveDTO);
        return Result.success();
    }

    @ApiOperation("车辆分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(VehiclePageQueryDTO vehiclePageQueryDTO){
        log.info("车辆分页查询,{}",vehiclePageQueryDTO);
        PageResult pageResult=vehicleService.page(vehiclePageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("根据id批量删除")
    @DeleteMapping("/delete")
    public Result<String> deleteBatch(@RequestParam List<Integer> ids){
        log.info("根据id批量删除,{}",ids);
        vehicleService.deleteBatch(ids);
        return Result.success();
    }

}
